home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77671_telnetadmin_prop.asp < prev    next >
Encoding:
Text File  |  2003-02-21  |  15.2 KB  |  443 lines

  1. <%@ Language=VBScript   %>
  2. <%    Option Explicit     %>
  3. <%
  4.     '------------------------------------------------------------------------- 
  5.     ' telnetadmin_prop.asp : get's and set's the telnet service properties.
  6.     '
  7.     ' Copyright (c) Microsoft Corporation.  All rights reserved. 
  8.     '
  9.     ' Date            Description
  10.     ' 28-Feb-01        Creation date
  11.     '-------------------------------------------------------------------------
  12. %>
  13.     <!-- #include virtual="/admin/inc_framework.asp" -->
  14. <%
  15.     '-------------------------------------------------------------------------
  16.     ' Global Constants and Variables
  17.     '-------------------------------------------------------------------------
  18.     Dim rc                                         'framework variables
  19.     Dim page                                     'framework variables
  20.     
  21.     Dim idTabGeneral                             'framework variables
  22.  
  23.     Const WBEMFLAG = 131072                         'Wmi constant to save wmi settings
  24.     
  25.     '-------------------------------------------------------------------------
  26.     ' Global Form Variables
  27.     '-------------------------------------------------------------------------
  28.     Dim F_strTelnetSvc                             'contains Value True if telnet service is running 
  29.                                                     '  else contains false
  30.     Dim F_strEnableTelnetAccess                     'Used to set the Telnet Service properties
  31.     
  32.     '------------------------------------------------------------------------
  33.     'Start of localization content
  34.     '------------------------------------------------------------------------
  35.     
  36.     Dim L_PAGETITLE_TEXT                         'Page title text
  37.     Dim L_GENERALTAB_TEXT                         'General Tab text
  38.     Dim L_ENABLETELNETACCESS_TEXT                 'Enable telnet access checkbox text
  39.     
  40.     'error messages
  41.     Dim L_TELNETSERVICENOTINSTALLED_ERRORMESSAGE  'if telnet service is not installed
  42.                                                     'this error message will be displayed            
  43.     Dim L_UNABLETOSETTHEPROPERTIES_ERRORMESSAGE      'if unable to set properties 
  44.                                                      'this error message will be displayed
  45.     
  46.     L_PAGETITLE_TEXT = GetLocString("telnet.dll", "&H40360003", "")
  47.     L_GENERALTAB_TEXT=GetLocString("telnet.dll", "&H40360004", "")
  48.     L_ENABLETELNETACCESS_TEXT=GetLocString("telnet.dll", "&H40360005", "")
  49.     
  50.     L_TELNETSERVICENOTINSTALLED_ERRORMESSAGE=GetLocString("telnet.dll", "&HC0360007", "")
  51.     L_UNABLETOSETTHEPROPERTIES_ERRORMESSAGE=GetLocString("telnet.dll", "&HC0360006", "")
  52.     
  53.     '------------------------------------------------------------------------
  54.     'END of localization content
  55.     '------------------------------------------------------------------------
  56.     
  57.     ' Create a Tabbed Property Page
  58.     rc = SA_CreatePage(L_PAGETITLE_TEXT,"", PT_TABBED, page )
  59.     
  60.     ' Add one tab
  61.     rc = SA_AddTabPage( page, L_GENERALTAB_TEXT, idTabGeneral)
  62.     
  63.     
  64.     ' Show the page
  65.     rc = SA_ShowPage( page )
  66.     
  67.     '-------------------------------------------------------------------------
  68.     'Function:                OnInitPage()
  69.     'Description:            Called to signal first time processing for this page.
  70.     '                        Use this method to do first time initialization tasks
  71.     'Input Variables:        PageIn,EventArg
  72.     'Output Variables:        PageIn,EventArg
  73.     'Returns:                True/False
  74.     'Global Variables:        In:L_TELNETSERVICENOTINSTALLED_ERRORMESSAGE-Displays
  75.     '                          error message when telnet service is not installed.            
  76.     '-------------------------------------------------------------------------    
  77.     Public Function OnInitPage(ByRef PageIn, ByRef EventArg)
  78.         Call SA_TraceOut( "telnetadmin_prop.asp", "OnInitPage")
  79.         
  80.         'checking whether Telnet service is installed or not.
  81.         If Not isServiceInstalled(getWMIConnection(CONST_WMI_WIN32_NAMESPACE),"TlntSvr") Then    
  82.             Call SA_TraceOut( "telnetadmin_prop.asp", "Telnet service is not Installed")
  83.             Call SA_ServeFailurePage( L_TELNETSERVICENOTINSTALLED_ERRORMESSAGE)
  84.             Exit Function
  85.             OnInitPage=False
  86.         End If 
  87.         
  88.         'getting default telnet service properties
  89.         GetTelenetSvcProp()
  90.         OnInitPage = TRUE
  91.     End Function
  92.     
  93.     '-------------------------------------------------------------------------
  94.     'Function:                OnPostBackPage()
  95.     'Description:            Called to signal that the page has been posted-back.
  96.     'Input Variables:        PageIn,EventArg
  97.     'Output Variables:        None
  98.     'Returns:                True/False
  99.     'Global Variables:        In:F_strTelnetSvc
  100.     '                        Out:F_strEnableTelnetAccess
  101.     '-------------------------------------------------------------------------
  102.     Public Function OnPostBackPage(ByRef PageIn, ByRef EventArg)
  103.         Call SA_TraceOut( "telnetadmin_prop.asp", "OnPostBackPage")
  104.         
  105.         'getting the value when the form is submitted
  106.         F_strTelnetSvc= Request.form("chkEnableTelnetAccess")
  107.         
  108.         'checking whether the enable telnet checkbox is enabled or not
  109.         If F_strTelnetSvc then
  110.             F_strEnableTelnetAccess="CHECKED"
  111.         Else
  112.             F_strEnableTelnetAccess=""
  113.         End If    
  114.         OnPostBackPage = TRUE
  115.     End Function
  116.     
  117.     '-------------------------------------------------------------------------
  118.     'Function:                OnServeTabbedPropertyPage()
  119.     'Description:            Called when the page needs to be served.Use this 
  120.     '                        method to serve content
  121.     'Input Variables:        PageIn,EventArg,iTab,bIsVisible
  122.     'Output Variables:        PageIn,EventArg
  123.     'Returns:                True/False
  124.     'Global Variables:        None
  125.     '            TRUE to indicate not problems occured. FALSE to indicate errors.
  126.     '            Returning FALSE will cause the page to be abandoned.
  127.     '-------------------------------------------------------------------------    
  128.     Public Function OnServeTabbedPropertyPage(ByRef PageIn, _
  129.                                                     ByVal iTab, _
  130.                                                     ByVal bIsVisible, ByRef EventArg)
  131.         Call SA_TraceOut( "telnetadmin_prop.asp", "OnServeTabbedPropertyPage")                                                    
  132.         ' Emit Web Framework required functions
  133.         If (iTab = 0) Then
  134.             Call ServeCommonJavaScript()
  135.         End If
  136.  
  137.         ' Emit content for the requested tab
  138.         Select Case iTab
  139.             Case idTabGeneral
  140.                 Call ServeTab1(PageIn, bIsVisible)
  141.             Case Else
  142.                 SA_TraceOut "telnetadmin_prop.asp", _
  143.                     "OnServeTabbedPropertyPage unrecognized tab id: " + CStr(iTab)    
  144.         End Select
  145.         OnServeTabbedPropertyPage = TRUE
  146.     End Function
  147.     
  148.     '-------------------------------------------------------------------------
  149.     'Function:                OnSubmitPage()
  150.     'Description:            Called when the page has been submitted for processing.
  151.     '                        Use this method to process the submit request.
  152.     'Input Variables:        PageIn,EventArg
  153.     'Output Variables:        None
  154.     'Returns:                True/False
  155.     'Global Variables:        None
  156.     '-------------------------------------------------------------------------
  157.     Public Function OnSubmitPage(ByRef PageIn, ByRef EventArg)
  158.         Call SA_TraceOut( "telnetadmin_prop.asp", "OnSubmitPage")    
  159.         OnSubmitPage =SetTelenetSvcProp()
  160.     End Function
  161.  
  162.     '-------------------------------------------------------------------------
  163.     'Function:                OnClosePage()
  164.     'Description:            Called when the page is about closed.Use this method
  165.     '                        to perform clean-up processing
  166.     'Input Variables:        PageIn,EventArg
  167.     'Output Variables:        PageIn,EventArg
  168.     'Returns:                True/False
  169.     'Global Variables:        None
  170.     '-------------------------------------------------------------------------
  171.     Public Function OnClosePage(ByRef PageIn, ByRef EventArg)
  172.         Call SA_TraceOut( "telnetadmin_prop.asp", "OnClosePage")    
  173.         OnClosePage = TRUE
  174.     End Function
  175.     
  176.     '-------------------------------------------------------------------------
  177.     'Function name:            GetTelenetSvcProp
  178.     'Description:            Get TelnetService properties from the appliance
  179.     'Input Variables:        None
  180.     'Output Variables:        None
  181.     'Returns:                True/False
  182.     'Global Variables:        In:L_(*)-Localization content
  183.     '                        Out:F_strTelnetSvc
  184.     '                        Out:F_strEnableTelnetAccess
  185.     '--------------------------------------------------------------------------
  186.     Function GetTelenetSvcProp
  187.         Err.Clear
  188.         on Error resume next
  189.         
  190.         Dim objService        'To get wmi connection
  191.         Dim strWMIpath        'To get wmi path
  192.         Dim objTelnetSvc    'To get wmi class instance
  193.         
  194.         'Getting wmi connection
  195.         Set objService=GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  196.         
  197.         If Err.number<>0 then
  198.             Call SA_TraceOut( "telnetadmin_prop.asp", "Wmi connection Failed-GetTelenetSvcProp()")    
  199.             Call SA_ServeFailurePage( L_WMI_CONNECTIONFAIL_ERRORMESSAGE)
  200.             GetTelenetSvcProp=False
  201.             Exit Function
  202.         End If    
  203.         
  204.         'Telnet service path
  205.         strWMIpath = "Win32_Service.Name='TlntSvr'" 
  206.         
  207.         'taking the instance of telnet service class 
  208.         Set objTelnetSvc=objService.get(strWMIpath)
  209.         
  210.         If Err.number<>0 then
  211.             Call SA_TraceOut( "telnetadmin_prop.asp", "Wmi Class Instance Failed-GetTelenetSvcProp()")    
  212.             Call SA_ServeFailurePage( L_WMI_INSTANCEFAIL_ERRORMESSAGE)
  213.             GetTelenetSvcProp=False
  214.             Exit Function
  215.         End If    
  216.         
  217.         'objTelnetSvc.Started returns true if telnet service is running.
  218.         '  otherewise returns false
  219.         F_strTelnetSvc=objTelnetSvc.Started
  220.         
  221.         If F_strTelnetSvc then
  222.             F_strEnableTelnetAccess="CHECKED"
  223.         Else
  224.             F_strEnableTelnetAccess=""
  225.         End If    
  226.             
  227.         GetTelenetSvcProp=True
  228.         
  229.         'Destroying dynamically created objects
  230.         Set objService=Nothing
  231.         Set objTelnetSvc=Nothing
  232.         
  233.     End function
  234.     
  235.     '-------------------------------------------------------------------------
  236.     'Function name:            SetTelenetSvcProp
  237.     'Description:            Setting the properties of the Telnet service
  238.     'Input Variables:        None
  239.     'Output Variables:        None
  240.     'Returns:                (True / Flase )
  241.     'Global Variables:        In:F_strTelnetSvc-'contains Value True if telnet service
  242.     '                         is running else contains false
  243.     '                        In:L_(*)-Localization content
  244.     '--------------------------------------------------------------------------
  245.     Function SetTelenetSvcProp
  246.         Err.Clear
  247.         on Error resume next
  248.         
  249.         Dim objService        'To get wmi connection
  250.         Dim strWMIpath        'To get wmi path
  251.         Dim objTelnetSvc    'To get wmi class instance
  252.         
  253.         'Getting wmi connection
  254.         Set objService=GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  255.         
  256.         If Err.number<>0 then
  257.             Call SA_TraceOut( "telnetadmin_prop.asp", "Wmi connection Failed-SetTelenetSvcProp()")    
  258.             Call SA_ServeFailurePage( L_WMI_CONNECTIONFAIL_ERRORMESSAGE)
  259.             SetTelenetSvcProp=False
  260.             Exit Function
  261.         End If    
  262.         
  263.         'Telnet service path
  264.         strWMIpath = "Win32_Service.Name='TlntSvr'" 
  265.         
  266.         'taking the instance of telnet service instance
  267.         Set objTelnetSvc=objService.get(strWMIpath)
  268.         
  269.         If Err.number<>0 then
  270.             Call SA_TraceOut( "telnetadmin_prop.asp", "Wmi Class Instance Failed-SetTelenetSvcProp()")    
  271.             Call SA_ServeFailurePage(L_WMI_INSTANCEFAIL_ERRORMESSAGE)
  272.             SetTelenetSvcProp=False
  273.             Exit Function
  274.         End If    
  275.         'setting the telnet service properties
  276.         If F_strTelnetSvc then
  277.             'if enable telnet access checkbox is checked,setting the telnet service to automatic,
  278.             ' and starting the service.
  279.             If Lcase(objTelnetSvc.StartMode) <> Lcase("Auto") then
  280.                 objTelnetSvc.ChangeStartMode("Automatic")
  281.             end If    
  282.                 objTelnetSvc.StartService()
  283.         Else    
  284.             'if enable telnet access checkbox is not checked,setting the telnet service to disabled,
  285.             ' and stopping the service.
  286.             objTelnetSvc.ChangeStartMode("Disabled")
  287.             objTelnetSvc.StopService()
  288.         End If    
  289.         
  290.         'saving the wmi settings
  291.         'objTelnetSvc.Put_(WBEMFLAG)
  292.         
  293.         If Err.number <> 0 then
  294.             Call SA_TraceOut( "telnetadmin_prop.asp", "Failed to Set TelnetService Properties" )
  295.             SetErrMsg L_UNABLETOSETTHEPROPERTIES_ERRORMESSAGE
  296.             SetTelenetSvcProp = false
  297.             Exit function
  298.         End If
  299.         
  300.         SetTelenetSvcProp=True
  301.         
  302.         'Destroying dynamically created objects
  303.         Set objService=Nothing
  304.         Set objTelnetSvc=Nothing
  305.     End Function
  306.     
  307.     '-------------------------------------------------------------------------
  308.     'Function:                ServeTab1
  309.     'Description:            Serves in getting the page for tab1
  310.     'Input Variables:        PageIn,bIsVisible
  311.     'Output Variables:        PageIn
  312.     'Returns:                gc_ERR_SUCCESS
  313.     'Global Variables:        L_(*)All
  314.     '                        F_(*) All            
  315.     '-------------------------------------------------------------------------
  316.     Function ServeTab1(ByRef PageIn, ByVal bIsVisible)
  317.             
  318.         If ( bIsVisible ) Then
  319.         
  320.         %>
  321.             <TABLE WIDTH=300 VALIGN=middle ALIGN=left BORDER=0 CELLSPACING=0 CELLPADDING=2 class="TasksBody">
  322.                 <TR>
  323.                     <TD>
  324.                         <INPUT TYPE="CHECKBOX"   NAME ="chkEnableTelnetAccess"  VALUE="<%=F_strTelnetSvc%>" <%=F_strEnableTelnetAccess%> onclick="storeEnableAccessVals()">
  325.                         <%=L_ENABLETELNETACCESS_TEXT%>
  326.                     </TD>
  327.                 <TR>
  328.             </TABLE>
  329.             
  330.         <%else%>
  331.         
  332.             <INPUT TYPE="hidden" NAME ="chkEnableTelnetAccess"  VALUE="<%=F_strTelnetSvc%>">
  333.         
  334.         <%    
  335.          End If
  336.          
  337.         ServeTab1 = gc_ERR_SUCCESS
  338.     End Function
  339.  
  340.     '-------------------------------------------------------------------------
  341.     'Function:                ServeCommonJavaScript
  342.     'Description:            Serves in initialiging the values,setting the form
  343.     '                        data and validating the form values
  344.     'Input Variables:        None
  345.     'Output Variables:        None
  346.     'Returns:                None
  347.     'Global Variables:        L_PASSWORDNOTMATCH_ERRORMESSAGE
  348.     '-------------------------------------------------------------------------
  349.     Function ServeCommonJavaScript()
  350.     %>
  351.         <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  352.         </script>
  353.         <script language="JavaScript">
  354.         // Init Function
  355.         
  356.         function Init()
  357.         {
  358.             return true;
  359.         }
  360.         
  361.         function storeEnableAccessVals()
  362.         {
  363.             var objForm        = eval("document.frmTask")
  364.             var objEnableAccess = objForm.chkEnableTelnetAccess
  365.         
  366.             if(objEnableAccess.checked == true)
  367.                 objForm.chkEnableTelnetAccess.value = "true"
  368.             else
  369.                 objForm.chkEnableTelnetAccess.value= "false"                                
  370.         }
  371.             
  372.         // ValidatePage Function
  373.         // Returns: True if the page is OK, false if error(s) exist. 
  374.         function ValidatePage()
  375.         {
  376.             return true;
  377.         }
  378.         
  379.         // SetData Function
  380.         function SetData()
  381.         {
  382.             return true;
  383.         }
  384.         </script>
  385.     <%
  386.     End Function
  387.     '-------------------------------------------------------------------------
  388.     'Function name:        isServiceInstalled
  389.     'Description:helper Function to chek whether the function is there or not
  390.     'Input Variables:    objService    - object to WMI
  391.     '                    strServiceName    - Service name
  392.     'Output Variables:    None
  393.     'Returns:            (True/Flase)                
  394.     'GlobalVariables:    None
  395.     '-------------------------------------------------------------------------
  396.     Function isServiceInstalled(ObjWMI,strServiceName)
  397.         Err.clear
  398.         on error resume next
  399.             
  400.         Dim strService   
  401.         
  402.         strService = "name=""" & strServiceName & """"
  403.         isServiceInstalled = IsValidWMIInstance(ObjWMI,"Win32_Service",strService)                  
  404.         
  405.     end Function
  406.     
  407.     '-------------------------------------------------------------------------
  408.     'Function name:        IsValidWMIInstance
  409.     'Description:        Checks the instance for valid ness.
  410.     'Input Variables:    objService    - object to WMI
  411.     '                    strClassName    - WMI class name
  412.     '                    strPropertyName    - Property name of the class
  413.     '
  414.     'Output Variables:    None
  415.     'Returns:            Returns true on Valid Instance ,
  416.     '                    False on invalid and also on Error
  417.     ' Checks whether the given instance is valid in WMI.Returns true on valid
  418.     ' false on invalid or Error.
  419.     '-------------------------------------------------------------------------
  420.     Function IsValidWMIInstance(objService,strClassName,strPropertyName)
  421.         Err.Clear
  422.         On Error Resume Next
  423.  
  424.         Dim strInstancePath
  425.         Dim objInstance
  426.  
  427.         strInstancePath = strClassName & "." & strPropertyName
  428.         
  429.         Set objInstance = objservice.Get(strInstancePath)
  430.  
  431.         if NOT isObject(objInstance) or Err.number <> 0 Then
  432.             IsValidWMIInstance = FALSE
  433.             Err.Clear
  434.         Else
  435.             IsValidWMIInstance = TRUE
  436.         End If
  437.         
  438.         'clean objects
  439.         Set objInstance=nothing
  440.         
  441.     End Function
  442. %>
  443.